<?php 
/**
 * 用户管理控制器
 */
class UserController extends CommonController{
	private $model;
	public function __init(){
		
		parent::__init();
		$this->model = K('User');
	}
	public function index(){
		if(!isset($_SESSION['uid'])) $this->error('请登录用户');
		//调配原有数据
		$oldData = $this->model->where("uid={$_SESSION['uid']}")->find();
		$this->assign('oldData',$oldData);
		//修改数据
		if(IS_POST){	
			$data = array(
				'uid'	=> $_SESSION['uid'],
				'face'  => Q('post.face'),
				'nick'	=> Q('post.nick'),
				'intro'	=> Q('post.intro')
			);

			$this->model->update($data);
			$this->success('资料修改成功');
		}
		$this->navigation();
		$this->display();
	}
	
	/**
	 * 上传插件 处理
	 */
	public function upload(){
	     $upload = new Upload('Upload/user/' . date('y/m'));
		 $file = $upload->upload();
		 if (empty($file)) {
		 	$this->ajax('上传失败');
		 } else {
		 	$data = $file[0];
			$this->ajax($data);
		 }
	}
	
	
	/***
	 * 异步修改密码
	 */
	public function alter(){
		if(!IS_AJAX) $this->error('非法请求');
		$userData = K('User')->where("uid={$_SESSION['uid']}")->find();
		if(md5(Q('post.oldpass'))==$userData['password']){
			$data = array(
				'uid' => $_SESSION['uid'],
				'password' => md5(Q('post.newpass'))
		
			);
			K('User')->update($data);
			$error = 0;
		}else{
			$error = 1;
		}
		
		echo $error;die;
		
		
	}
	
	/**
	 * 加载用户喜欢模板
	 */
	public function likeGoods(){
		$uid = Q('get.uid',0,'intval');
		//获取此用户喜欢的产品信息
		$likesData = M('')->join('__goods_user__ as gu JOIN __goods__ as g ON gu.goods_gid=g.gid')->where("user_uid={$uid}")->all();
		$likesCount = count($likesData);
		$this->assign('likesCount',$likesCount);
		$this->assign('likesData',$likesData);
		//获取此用户信息
		$userData = K('User')->where("uid={$uid}")->find();
		$this->assign('userData',$userData);
		$this->navigation();
		$this->display();
	}
	
	
	
}



















 ?>